package com.wxh.multithread;

/**
 * @ClassName: TestThreadState
 * @Description: 测试线程状态
 * @Author wxh
 * @Date: 2021/12/30 14:23
 * @Version V1.0.0
 * @Since 1.8
 */
public class TestThreadState {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("////////////////");
        });

        // 观察线程状态
        Thread.State state = thread.getState();
        // NEW
        System.out.println("线程状态： "+state);

        // 启动线程后，状态
        thread.start();
        state = thread.getState();
        // RUNNABLE
        System.out.println("线程状态： "+state);

        // 线程未终止
        while(state != Thread.State.TERMINATED){
            Thread.sleep(1000);
            state = thread.getState();
            System.out.println("线程状态： "+state);
        }
    }
}
